package com.antball.config;


import com.antball.model.User;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.w3c.dom.Element;

/**
 * @Auther: huangsj
 * @Date: 2019/7/18 13:12
 * @Description:
 */
public class UserBeanDefinitionParse extends AbstractSingleBeanDefinitionParser {

    private static final String USERNAME_ATTRIBUTE = "username";
    private static final String PASSWORD_ATTRIBUTE = "password";


    /**
     * 加上这个可以不用设置id属性
     * @return
     */
    @Override
    protected boolean shouldGenerateIdAsFallback() {
        return true;
    }

    @Override
    protected Class<?> getBeanClass(Element element) {
        return User.class;
    }

    @Override
    protected void doParse(Element element, BeanDefinitionBuilder builder) {
        NamespaceUtils.setValueIfAttributeDefined(builder, element, USERNAME_ATTRIBUTE);
        NamespaceUtils.setValueIfAttributeDefined(builder, element, PASSWORD_ATTRIBUTE);
    }
}
